package cn.lyq;

import cn.lyq.db.ConnectDB;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;

public class Controller {
	@FXML
	private Button addWordButton;
	@FXML
	private TextField englishText;
	@FXML
	private TextField chineseText;
	
	@FXML
	public void onAddWordButton(ActionEvent e) {
		String english = englishText.getText();
		String chinese = chineseText.getText();
		
		boolean ok = new ConnectDB().addWord(english, chinese);
		
		if(ok) {
			// 显示一个提示信息 对话框
			Alert alert = new Alert(AlertType.INFORMATION);
			alert.setTitle("信息");
			alert.setHeaderText("单词已经成功进入数据库");
			alert.setContentText("现在可以继续录入下一个单词");
			alert.showAndWait(); //此语句会堵塞并等待“确定"按钮"按下
			
			// 清空输入框
			englishText.setText("");
			chineseText.setText("");
		}
	}
}
